package com.imau.controller;

import com.imau.bean.User;
import com.imau.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *  1. 确定请求方法类型：POST  GET DELETE PUT
 *  2. /{id}
 *  3. @PathVariable("id") 获取路径参数，赋值给形参id
 */
@RestController
//@ResponseBody
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/{id}")
    public String findById(@PathVariable("id") Integer id)
    {
        System.out.println("findById......id=="+id);

        return "findById";
    }

    @DeleteMapping(value = "/{id}")
    public String deleteById(@PathVariable("id") Integer userId)
    {
        System.out.println("deleteById......id=="+userId);

        return "deleteById";
    }

    @PostMapping
    public User saveUser(@RequestBody User user)
    {
        System.out.println("user="+user);

        return user;
    }

    @PutMapping
    public String updateUser(@RequestBody User user)
    {
        System.out.println("user="+user);

        return "updateUser";
    }


    @GetMapping
    public String getUsers()
    {
        System.out.println("getUsers=");

        return "getUsers";
    }
}
